package main.entity;

import javafx.scene.Group;
import javafx.scene.image.ImageView;
import javafx.scene.paint.Color;
import javafx.scene.shape.Line;
import javafx.scene.shape.Rectangle;

import static main.utils.RiverConstants.RAFT_HEIGHT;
import static main.utils.RiverConstants.RAFT_WIDTH;
import static main.utils.RiverUtils.newImage;

public class Raft extends Group {
    private Line paddleLeft;
    private Line paddleRight;
    //    private ImageView body;
    private Rectangle body;
    private ImageView sail;

    private int paddleLeftInitialX;
    private int paddleRightInitialX;
    private int x;
    private int y;

    public Raft(int raftX, int raftY) {
        this.x = raftX;
        this.y = raftY;

        paddleLeft = new Line();
        paddleLeft.setStrokeWidth(2);
        getChildren().add(paddleLeft);

//        body = new ImageView();
        body = new Rectangle(RAFT_WIDTH, RAFT_HEIGHT);
        getChildren().add(body);

        sail = new ImageView();
//        getChildren().add(sail);

        paddleRight = new Line();
        paddleRight.setStrokeWidth(2);
        getChildren().add(paddleRight);

        updatePositions();
    }

    public void updatePositions() {
        paddleLeftInitialX = x + 30;
        paddleLeft.setStartX(x + RAFT_WIDTH / 2 + 8);
        paddleLeft.setEndX(paddleLeftInitialX);
        paddleLeft.setStartY(y);
        paddleLeft.setEndY(y - RAFT_HEIGHT / 4);

//        body.setImage(newImage("img/raft-body.png", RAFT_WIDTH, RAFT_HEIGHT));
        body.setX(x);
        body.setY(y);
        body.setFill(Color.BROWN);

        sail.setImage(newImage("img/raft-sail.png", RAFT_WIDTH, RAFT_HEIGHT + 20));
        sail.setX(x);
        sail.setY(y - RAFT_HEIGHT - 20);

        paddleRightInitialX = x + RAFT_WIDTH-15;
        paddleRight.setStartX(x + RAFT_WIDTH / 2);
        paddleRight.setEndX(paddleRightInitialX);
        paddleRight.setStartY(y + RAFT_HEIGHT - 5);
        paddleRight.setEndY(y + RAFT_HEIGHT + RAFT_HEIGHT / 4);
    }

    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }

    public Line getPaddleLeft() {
        return paddleLeft;
    }

    public Line getPaddleRight() {
        return paddleRight;
    }

    public int getPaddleLeftInitialX() {
        return paddleLeftInitialX;
    }

    public int getPaddleRightInitialX() {
        return paddleRightInitialX;
    }
}
